local inst = {
}

function inst:run(out)
    self.logger = out

    self:Line("\n# 关卡信息统计")
    for i=1, 150 do
        local content = CS.Logic.ProtocalDetailByLevelId(i)
        if content then
            local pkg = table.deserialize(content)
            local data = pkg.gameData
            self:Line("\n## 关卡[" ..i .."]")
            self:Line("\n + 步数:" ..data.moveLimit)
            self:Line("\n + 难度:" ..data.difficulty)

            local orderList = data.orderList
            self:Line("\n### 目标")
            for _, order in pairs(orderList) do
                local idx = tonumber(order.k)
                local name = ENUM_TILE_NAMES[idx] or ENUM_SPECIAL_NAMES[idx] or tostring(order.k)
                self:Line("\n + " ..name .." " ..order.v)
            end

            local tiles = self:ProcessMap(data.tileMap)
            self:Line("\n### 地格")
            for _,v in pairs(tiles) do
                self:Append(ENUM_TILE_NAMES[v] .. " ")
            end

            local specials = self:ProcessMap(data.specialAnimalMap)
            self:Line("\n### 特效")
            for _,v in pairs(specials) do
                self:Append(ENUM_SPECIAL_NAMES[v] .. " ")
            end
        end
    end
end

function inst:ProcessMap(data)
    local results = {}
    for k, line in ipairs(data) do
        for k, item in ipairs(line) do
            for k, ceil in ipairs(item) do
                if ceil ~= 0 then
                    table.insertIfNotExist(results, ceil)
                end
            end
        end
    end
    return results
end

function inst:ProcessSpecialMap(val)
    self.logger:write(val .."\n")
end

function inst:Append(val)
    self.logger:write(val)
end

function inst:Line(val)
    self.logger:write(val .."\n")
end

return inst